<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="ot" uri="http://www.ideyatech.com/tides"%>
<%@ taglib prefix="idy" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<idy:bs-iris-header title_webpage="title.patient" arg="${patient.fullName}">
	<link rel="stylesheet" type="text/css" href="${url_style}/iris-patient-profile.css" />
	
</idy:bs-iris-header>

<div class="page-body">
	<div>
		<div id="message">
			<c:if test="${param.action eq 'delete'}">
				<div class="alert alert-success">
					<strong>Alright!</strong> ${param.item} successfully deleted.
				</div>
			</c:if>
			<c:if test="${param.action eq 'update'}">
				<div class="alert alert-success">
					<strong>Alright!</strong> ${param.item} successfully updated.
				</div>
			</c:if>
		</div>
		<div class="pull-left">
			<img src="${url_context}/patient-image.jspx?patientId=${patient.id}&imageSize=large" width="250" height="250" class="profile-picture img-polaroid"/>
			<div class="text-center profile-picture-options"><a class="change-photo-button pointer">Update</a></div>
		</div>
		<div class="patient-information pull-left">
			<a class="btn btn-primary btn-small pull-right" href="${url_context}/patient/form.jspx?id=${patient.id}&action=update"><i class="icon-edit icon-white"></i> Update Details</a>
			<h3>${patient.fullName} <c:if test="${!empty patient.nickname}">(${patient.nickname})</c:if></h3>
			
			<dl class="dl-horizontal patient-info">
				<dt>Age</dt>
				<dd>${patient.age}</dd>
				<dt>Gender</dt>
				<dd>${patient.gender.value}</dd>
				<dt>Birthdate</dt>
				<dd><fmt:formatDate value='${patient.birthdate}' pattern="MMMM dd, yyyy"/></dd>
				<dt>Address</dt>
				<dd>${patient.address}<c:if test="${empty patient.address}"><span class="muted">Not specified</span></c:if></dd>
				<dt>Patient since</dt>
				<dd><fmt:formatDate value='${patient.registrationDate}' pattern="MMMM yyyy"/></dd>
				<dt>Email</dt>
				<dd>${patient.emailAddress}<c:if test="${empty patient.emailAddress}"><span class="muted">Not specified</span></c:if></dd>
				<dt>Landline no.</dt>
				<dd>
					<c:set var="landlineSize" value="${fn:length(patient.landlineNumbers)}"/>
					<c:forEach items="${patient.landlineNumbers}" var="landline" varStatus="status">
						${landline.number}<c:if test="${status.index < landlineSize-1}">, </c:if>
					</c:forEach>
					<c:if test="${empty patient.landlineNumbers}"><span class="muted">Not specified</span></c:if>
				</dd>
				<dt>Mobile no.</dt>
				<dd>
					<c:set var="mobileSize" value="${fn:length(patient.mobileNumbers)}"/>
					<c:forEach items="${patient.mobileNumbers}" var="mobile" varStatus="status">
						${mobile.number}<c:if test="${status.index < mobileSize-1}">, </c:if>
					</c:forEach>
					<c:if test="${empty patient.mobileNumbers}"><span class="muted">Not specified</span></c:if>
				</dd>
			</dl>
		</div>
	<div class="clear"></div>
	</div>
	
	<div>
		<a target="_blank" href="${url_context}/generate-report.jspx?SUBREPORT_DIR=${jasperPath}&reportFile=patient-summary&reportFormat=pdf&reportName=patient-summary&PATIENT_ID=${patient.id}">Print Patient Summary</a>
	</div>
	
	<br/>
	<c:if test="${not empty patient.patientAllergies or not empty patient.patientDiseases}">
		
		<div class="well">
			<strong class="text-warning">Heads Up!</strong><br/>
			<ul>
				<c:if test="${not empty patient.presentDiseases}">
					<li>
						Patient is currently suffering from 
						<c:set var="presentDiseaseSize" value="${fn:length(patient.presentDiseases)}"/>
						<c:forEach items="${patient.presentDiseases}" var="patientDisease" varStatus="status">
							<c:if test="${status.index eq presentDiseaseSize-1 and presentDiseaseSize != 1}"> and </c:if><span class="text-warning">${patientDisease.disease.name}</span><c:if test="${status.index < presentDiseaseSize-1}">, </c:if><c:if test="${status.index eq presentDiseaseSize-1}">. </c:if>
						</c:forEach>
					</li>
				</c:if>
				
				<c:if test="${not empty patient.pastDiseases}">
					<li>
						Patient has a history of 
						<c:set var="pastDiseaseSize" value="${fn:length(patient.pastDiseases)}"/>
						<c:forEach items="${patient.pastDiseases}" var="patientDisease" varStatus="status">
							<c:if test="${status.index eq pastDiseaseSize-1 and pastDiseaseSize != 1}"> and </c:if><span class="text-warning">${patientDisease.disease.name}</span><c:if test="${status.index < pastDiseaseSize-1}">, </c:if><c:if test="${status.index eq pastDiseaseSize-1}">. </c:if>
						</c:forEach>
					</li>
				</c:if>
				
				<c:if test="${not empty patient.activeAllergies}">
					<li>
						Patient has allergic reactions to the following: 
						<c:set var="activeAllergiesSize" value="${fn:length(patient.activeAllergies)}"/>
						<c:forEach items="${patient.activeAllergies}" var="patientAllergy" varStatus="status">
							<c:if test="${status.index eq activeAllergiesSize-1 and activeAllergiesSize != 1}"> and </c:if><span class="text-warning">${patientAllergy.allergen.name}</span><c:if test="${status.index < activeAllergiesSize-1}">, </c:if><c:if test="${status.index eq activeAllergiesSize-1}">. </c:if>
						</c:forEach>
					</li>
				</c:if>
				
				<c:if test="${not empty patient.inactiveAllergies}">
					<li>
						Be careful with 
						<c:set var="inactiveAllergiesSize" value="${fn:length(patient.inactiveAllergies)}"/>
						<c:forEach items="${patient.inactiveAllergies}" var="patientAllergy" varStatus="status">
							<c:if test="${status.index eq inactiveAllergiesSize-1 and inactiveAllergiesSize != 1}"> and </c:if><span class="text-warning">${patientAllergy.allergen.name}</span><c:if test="${status.index < inactiveAllergiesSize-1}">, </c:if>
						</c:forEach>
						as patient previously had allergic reactions with them in the past.
					</li>
				</c:if>
			
			</ul>
		</div>
	</c:if>
	
	<div>
		<ul class="nav nav-tabs text-center no-bottom">
			<li class="active"><a onclick="switchTab('treatments')" class="pointer switch-tab" id="treatments">Treatments</a></li>
			<li><a onclick="switchTab('programs')" class="pointer switch-tab" id="programs">Programs</a></li>
			<li><a onclick="switchTab('files')" class="pointer switch-tab" id="files">Files</a></li>
		</ul>
		
		<div id="profile-menu-tab-wrapper">
		</div>
	</div>
</div>

<idy:bs-iris-footer>
	<script type="text/javascript" src="${url_script_lib}/jquery-1.7.2.js"></script>
	<script type="text/javascript" src="${url_context}/script/ideyatech-1.0/jquery.form.js"></script>

	<script type="text/javascript">
			
		function switchTab(tab){
			
			if(tab=="files"){
				IRIS.ajaxUtil.ajaxInclude('${url_context}/patient/file/upload.jspx?patientId=${patient.id}','profile-menu-tab-wrapper');
			} else {
				IRIS.ajaxUtil.ajaxInclude('${url_context}/patient/tab.jspx?id=${patient.id}&tab='+tab,'profile-menu-tab-wrapper');
			}
		}
		
		$(document).ready(function(){
			$('.switch-tab').parent().removeClass('active');
			<c:choose>
				<c:when test="${param.item eq 'Treatment'}">
					switchTab('treatments');
					$('#treatments').parent().addClass('active');
				</c:when>
				<c:when test="${param.item eq 'Program'}">
					switchTab('programs');
					$('#programs').parent().addClass('active');
				</c:when>
				<c:when test="${param.item eq 'File'}">
					switchTab('files');
					$('#files').parent().addClass('active');
				</c:when>
				
				<c:otherwise>
					switchTab('treatments');
					$('#treatments').parent().addClass('active');
				</c:otherwise>
			</c:choose>
			
			$('.switch-tab').click(function(){
				$('.switch-tab').parent().removeClass('active');
				$(this).parent().addClass('active');
				switchTab($(this).attr("id"));
				$('#message').addClass('hide');
			});
		});
		
		$('.change-photo-button').click(function(){
			TINY.box.show({
			    iframe: '${url_context}/upload-patient-photo.jspx?patientId=${patient.id}',
			    width: 600,
			    height: 300,
			    fixed: true
			});
		});
		
	</script>
</idy:bs-iris-footer>